<template>
  <Modal :width="600" v-model="model" @on-cancel='onCancel' :styles="{top: '13%'}">
    <p slot="header" >
      <span>经销商批量-移动</span>
    </p>
    <div class="ht400 scroll">
      <Form :label-width="60">
        <FormItem label="部门:" prop="departmentId">
          <DepartmentRadio v-if="model" v-model="form.departmentId" style="margin-top: -9px" />
        </FormItem>
      </Form>
    </div>
    <div slot="footer">
      <Button  size="large" type="text"  @click="onCancel">取消</Button>
      <Button type="primary" size="large"   @click="onDone">确认</Button>
    </div>
  </Modal>
</template>
<script>
import DepartmentRadio from '@/components/DepartmentRadio'
export default {
  components: {
    DepartmentRadio
  },
  props: {
  },
  created () {
  },
  data() {
    return {
      id: '',
      model: false,
      form: { departmentId: '', distributorIds: [] },
      loading: false,
      list: []
    }
  },
  methods: {
    open(ids) {
      this.model = true
      this.form.distributorIds = ids
      this.getData()
    },
    onCancel() {
      this.close()
    },
    onDone() {
      if (!this.form.departmentId) {
        this.$Notice.warning({ title: '请选择业务部门' })
        return
      }
      this.$jsonPost(`/department/move_distributor`, this.form).then(res => {
          this.$Notice.success({ title: '批量移动成功' })
          this.close()
          this.$emit('successMove')
      })
    },
    close() {
      this.model = false
    },
    getData () {
      this.$jsonPost('/department/listDepartmentTree').then(res => {
          const loop = (res) => {
            res.forEach(item => { 
                item.expand = false
                item.label = item.name
                if (item.children && item.children.length) {
                  loop(item.children)
                }
            })
          }
          loop(res)
          this.list = res
      })
    }
  }
}
</script>

